<?php

namespace App\Models\Order;

use Illuminate\Database\Eloquent\Model;

/**
 * 出库收款对账单
 */
class Outboundorderwithpay extends Model
{
    protected $table = 'outbound_order_orderwithpay';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];

    /**
     * 列表
     */
    public static function getList($request, $memberinfo, $isgetall)
    {
        $cpid = $memberinfo['cpid'] ?? 0;

        $query = self::orderBy('create_at', 'desc');

        //单据日期
        $start_time = $request->start_time;
        if ($start_time != '') {
            $query->where('order_date', '>=', $start_time);
        }

        $end_time = $request->end_time;
        if ($end_time != '') {
            $query->where('order_date', '<=', $end_time);
        }

        //客户名称
        $custom_id = $request->custom_id ?? 0;
        if ($custom_id > 0) {
            $query->where('custom_id', $custom_id);
        }

        $custom_name = $request->custom_name;
        if ($custom_name != '') {
            $query->where('custom_name', 'like', '%' . $custom_name . '%');
        }

        $settlement_company = $request->settlement_company ?? '';
        if ($settlement_company != '') {
            $query->where('settlement_company', 'like', '%' . $settlement_company . '%');
        }

        if ($cpid > 0) {
            $query->where('cpid', $cpid);
        }

        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
}
